package com.sxt.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sxt.sys.domain.Menu;
import com.sxt.sys.mapper.MenuMapper;
import com.sxt.sys.service.MenuService;
import com.sxt.sys.utils.DataGridView;
import com.sxt.sys.vo.MenuVo;

@Service
@Transactional
public class MenuServiceImpl implements MenuService{

	@Autowired
	private MenuMapper menuMapper;

	@Override
	public List<Menu> queryAllMenusForList(Menu menuVo) {
		return this.menuMapper.queryAllMenus(menuVo);
	}

	@Override
	public List<Menu> queryMenusByUserIdForList(MenuVo menuVo, Integer userId) {
		return this.menuMapper.queryMenusByUserIdForList(userId);
	}

	@Override
	public DataGridView queryAllMenu(MenuVo menuVo) {
		Page<Object> page=PageHelper.startPage(menuVo.getPage(), menuVo.getRows());
		List<Menu> list = this.menuMapper.queryAllMenus(menuVo);
		return new DataGridView(page.getTotal(), list);
	}

	@Override
	public void addMenu(MenuVo menuVo) {
		this.menuMapper.insertSelective(menuVo);
	}

	@Override
	public void updateMenu(MenuVo menuVo) {
		this.menuMapper.updateByPrimaryKeySelective(menuVo);
	}

	@Override
	public Integer queryChildrenNodeById(Integer id) {
		return this.menuMapper.queryChildrenNodeById(id);
	}

	@Override
	public void deleteMenu(MenuVo menuVo) {
		this.menuMapper.deleteByPrimaryKey(menuVo.getId());
	}

	@Override
	public List<Menu> queryMenusByRoleIdForList(Integer roleid,
			Integer available) {
		// TODO Auto-generated method stub
		return this.menuMapper.queryMenusByRoleIdForList(roleid, available);
	}
	
}
